package com.igoal.dao;

import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import com.igoal.entity.Company;
import com.igoal.utils.StringUtils;

@Repository("companyDAO")
public class CompanyDAOImpl extends GenericDaoHibernate<Company, Long>
		implements CompanyDAO {

	public CompanyDAOImpl() {
		super(Company.class);
	}
	
	public List<Company> getCompanyByNameAndCity(String name, String cityName, Long cityId){
		DetachedCriteria dc = DetachedCriteria.forClass(Company.class);
		if(!StringUtils.isBlank(name)){
			dc.add(Restrictions.eq("name", name));
		}
		if(!StringUtils.isBlank(cityName)){
			dc.add(Restrictions.eq("city.cityName", cityName));
		}
		if(cityId != null && cityId > 0L){
			dc.add(Restrictions.eq("city.id", cityId));
		}
		
		return findByCriteria(dc);
	}
}
